package com.ruoyi.dish.service;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dish.domain.DishMenu;
import com.ruoyi.dish.domain.vo.MenuSearchVo;
import com.ruoyi.dish.mapper.DishMenuMapper;
import com.ruoyi.human.domain.HuStore;
import com.ruoyi.human.mapper.HuStoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DishMenuService {
    @Autowired
    private DishMenuMapper dishMenuMapper;
    @Autowired
    private HuStoreMapper storeMapper;

    @Transactional(transactionManager = "transactionManager", rollbackFor = Exception.class)
    public void insert(DishMenu menu) {
        //根据商店id查询商店名称
        HuStore store = storeMapper.getStoreById(menu.getStoreId());
        menu.setStoreName(store.getStoreName());
        menu.setStoreAddress(store.getStoreAddress());
        menu.setContactPhone(store.getContactPhone());
        //将dishMenu中的数据添加到数据库中
        dishMenuMapper.insertMenu(menu);
    }

    public DishMenu getMenuById(String menuId) {
        return dishMenuMapper.selectMenuById(menuId);
    }
    //显示菜单
    public List<DishMenu> selectMenuList() {
        return dishMenuMapper.selectMenuList();
    }
    //模糊搜索
    public List<DishMenu> searchMenu(MenuSearchVo menuSearchVo) {
        return dishMenuMapper.searchMenu(menuSearchVo);
    }

}
